cc.Class({
    extends: cc.Component,

    properties: {
        //本轮得分文本
        scoreLabel: cc.Label,
        //最高分文本
        highScoreLabel: cc.Label,
        //重新开始按钮
        reStartBtn:cc.Node,
    },

    onLoad:function(){
        cc.audioEngine.playMusic(this.bgAudio, true);
        cc.director.preloadScene("Game");
        this.reStartBtn.on(cc.Node.EventType.TOUCH_START,this.reStart);
        console.log(cc.sys.localStorage.getItem("highScore"));
        var highScore;
        if(cc.sys.localStorage.getItem("highScore")){
            highScore = cc.sys.localStorage.getItem("highScore");
        }else{
            highScore = 0 ;
        }
        // var highScore = cc.sys.localStorage.getItem("highScore") || 0;
        var score = cc.sys.localStorage.getItem("score");
        if(Number(highScore) < Number(score))
        {
            cc.sys.localStorage.setItem("highScore",Number(score));
        }
        highScore = cc.sys.localStorage.getItem("highScore");
        this.highScoreLabel.string = `  ${highScore}`;
        this.scoreLabel.string = `  ${score}`;
    },
    reStart:function(){
        cc.director.loadScene("Game");
    },


});
